const express = require('express');
const app = express();
app.listen(9000, () => {
  console.log('服务器9000启动成功');
});
app.use(express.json());

// 1.终端输入命令npm i cors

// 2.引入cors模块
const cors = require('cors');

// 3.注册cors中间件
app.use(cors());

app.get('/middleware_cors_get', (req, res) => {
  console.log('query', req.query); // query { query_name: 'query' }
  res.end();
});

app.post('/middleware_cors_post', (req, res) => {
  console.log('body', req.body); // body { body_name: 'body' }
  res.end();
});